package com.goodwill.androidtest.kotlin_test.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import android.widget.Toast
import androidx.recyclerview.widget.RecyclerView
import com.goodwill.androidtest.R
import kotlinx.android.synthetic.main.item_list_layout.view.*

public class ItemListRvAdapter(var ctx: Context?, var data: MutableList<String>?) : RecyclerView.Adapter<ItemListHolder>() {

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemListHolder {
        var view = LayoutInflater.from(ctx).inflate(R.layout.item_list_layout, parent, false)
        return ItemListHolder(view)
    }

    override fun getItemCount(): Int {
        return data!!.size
    }

    override fun onBindViewHolder(holder: ItemListHolder, position: Int) {
        holder.textInfo!!.text = data!!.get(position)
        holder.textInfo!!.setOnClickListener {
            Toast.makeText(ctx!!, "click:$position",Toast.LENGTH_SHORT).show()
        }
    }
}

class ItemListHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
    var textInfo: TextView? = null
    init {
        textInfo = itemView.tv_item_name
    }

}
